Effect of UPSTM-Based
Decorrelation on Feature Discovery
Loading the
libraries
library("FRESA.CAD")
library(readxl)
library(igraph)
library(umap)
library(tsne)
library(entropy)
op <- par(no.readonly = TRUE)
pander::panderOptions('digits', 3)
pander::panderOptions('table.split.table', 400)
pander::panderOptions('keep.trailing.zeros',TRUE)
Material and
Methods
The Data
DARWIN <- read.csv("~/GitHub/FCA/Data/DARWIN/DARWIN.csv")
rownames(DARWIN) <- DARWIN$ID
DARWIN$ID <- NULL
DARWIN$class <- 1*(DARWIN$class=="P")
print(table(DARWIN$class))
#>
#> 0 1
#> 85 89
DARWIN[,1:ncol(DARWIN)] <- sapply(DARWIN,as.numeric)
signedlog <- function(x) { return (sign(x)*log(abs(1.0e12*x)+1.0))}
whof <- !(colnames(DARWIN) %in% c("class"));
DARWIN[,whof] <- signedlog(DARWIN[,whof])
Standarize the
names for the reporting
studyName <- "DARWIN"
dataframe <- DARWIN
outcome <- "class"
TopVariables <- 10
thro <- 0.80
cexheat = 0.15
Generaring the
report
Libraries
Some libraries
library(psych)
library(whitening)
library("vioplot")
library("rpart")
Data specs
pander::pander(c(rows=nrow(dataframe),col=ncol(dataframe)-1))
pander::pander(table(dataframe[,outcome]))
varlist <- colnames(dataframe)
varlist <- varlist[varlist != outcome]
largeSet <- length(varlist) > 1500
Scaling the
data
Scaling and removing near zero variance columns and highly
co-linear(r>0.99999) columns
### Some global cleaning
sdiszero <- apply(dataframe,2,sd) > 1.0e-16
dataframe <- dataframe[,sdiszero]
varlist <- colnames(dataframe)[colnames(dataframe) != outcome]
tokeep <- c(as.character(correlated_Remove(dataframe,varlist,thr=0.99999)),outcome)
dataframe <- dataframe[,tokeep]
varlist <- colnames(dataframe)
varlist <- varlist[varlist != outcome]
iscontinous <- sapply(apply(dataframe,2,unique),length) >= 5 ## Only variables with enough samples
dataframeScaled <- FRESAScale(dataframe,method="OrderLogit")$scaledData
The heatmap of the
data
numsub <- nrow(dataframe)
if (numsub > 1000) numsub <- 1000
if (!largeSet)
{
hm <- heatMaps(data=dataframeScaled[1:numsub,],
Outcome=outcome,
Scale=TRUE,
hCluster = "row",
xlab="Feature",
ylab="Sample",
srtCol=45,
srtRow=45,
cexCol=cexheat,
cexRow=cexheat
)
par(op)
}

Correlation
Matrix of the Data
The heat map of the data
if (!largeSet)
{
par(cex=0.6,cex.main=0.85,cex.axis=0.7)
#cormat <- Rfast::cora(as.matrix(dataframe[,varlist]),large=TRUE)
cormat <- cor(dataframe[,varlist],method="pearson")
cormat[is.na(cormat)] <- 0
gplots::heatmap.2(abs(cormat),
trace = "none",
# scale = "row",
mar = c(5,5),
col=rev(heat.colors(5)),
main = "Original Correlation",
cexRow = cexheat,
cexCol = cexheat,
srtCol=45,
srtRow=45,
key.title=NA,
key.xlab="|Pearson Correlation|",
xlab="Feature", ylab="Feature")
diag(cormat) <- 0
print(max(abs(cormat)))
}
[1]
0.9994118
The
decorrelation
DEdataframe <- IDeA(dataframe,verbose=TRUE,thr=thro)
#>
#> Included: 450 , Uni p: 0.006594985 , Uncorrelated Base: 139 , Outcome-Driven Size: 0 , Base Size: 139
#>
#>
1 <R=0.999,thr=0.900,N= 261>, Top: 91( 1 )[ 1 : 91 Fa= 90 : 0.900 ]( 90 , 166 , 0 ),<|>Tot Used: 256 , Added: 166 , Zero Std: 0 , Max Cor: 0.992
#>
2 <R=0.992,thr=0.900,N= 261>, Top: 16( 1 )[ 1 : 16 Fa= 105 : 0.900 ]( 16 , 26 , 90 ),<|>Tot Used: 258 , Added: 26 , Zero Std: 0 , Max Cor: 0.959
#>
3 <R=0.959,thr=0.900,N= 261>, Top: 2( 1 )[ 1 : 2 Fa= 107 : 0.900 ]( 2 , 2 , 105 ),<|>Tot Used: 258 , Added: 2 , Zero Std: 0 , Max Cor: 0.899
#>
4 <R=0.899,thr=0.800,N= 136>, Top: 65( 2 )[ 1 : 65 Fa= 144 : 0.800 ]( 59 , 67 , 107 ),<|>Tot Used: 339 , Added: 67 , Zero Std: 0 , Max Cor: 0.993
#>
5 <R=0.993,thr=0.900,N= 4>, Top: 2( 1 )[ 1 : 2 Fa= 145 : 0.900 ]( 2 , 2 , 144 ),<|>Tot Used: 339 , Added: 2 , Zero Std: 0 , Max Cor: 0.894
#>
6 <R=0.894,thr=0.800,N= 25>, Top: 12( 1 )[ 1 : 12 Fa= 147 : 0.800 ]( 12 , 13 , 145 ),<|>Tot Used: 343 , Added: 13 , Zero Std: 0 , Max Cor: 0.842
#>
7 <R=0.842,thr=0.800,N= 25>, Top: 1( 1 )[ 1 : 1 Fa= 147 : 0.800 ]( 1 , 1 , 147 ),<|>Tot Used: 343 , Added: 1 , Zero Std: 0 , Max Cor: 0.797
#>
8 <R=0.797,thr=0.800,N= 25>
#>
[ 8 ], 0.7971926 Decor Dimension: 343 Nused: 343 . Cor to Base: 213 , ABase: 88 , Outcome Base: 0
#>
varlistc <- colnames(DEdataframe)[colnames(DEdataframe) != outcome]
pander::pander(sum(apply(dataframe[,varlist],2,var)))
692
pander::pander(sum(apply(DEdataframe[,varlistc],2,var)))
123
pander::pander(entropy(discretize(unlist(dataframe[,varlist]), 256)))
4.57
pander::pander(entropy(discretize(unlist(DEdataframe[,varlistc]), 256)))
4.65
The decorrelation
matrix
if (!largeSet)
{
par(cex=0.6,cex.main=0.85,cex.axis=0.7)
UPSTM <- attr(DEdataframe,"UPSTM")
gplots::heatmap.2(1.0*(abs(UPSTM)>0),
trace = "none",
mar = c(5,5),
col=rev(heat.colors(5)),
main = "Decorrelation matrix",
cexRow = cexheat,
cexCol = cexheat,
srtCol=45,
srtRow=45,
key.title=NA,
key.xlab="|Beta|>0",
xlab="Output Feature", ylab="Input Feature")
par(op)
}

The correlation
matrix after decorrelation
if (!largeSet)
{
cormat <- cor(DEdataframe[,varlistc],method="pearson")
cormat[is.na(cormat)] <- 0
gplots::heatmap.2(abs(cormat),
trace = "none",
mar = c(5,5),
col=rev(heat.colors(5)),
main = "Correlation after IDeA",
cexRow = cexheat,
cexCol = cexheat,
srtCol=45,
srtRow=45,
key.title=NA,
key.xlab="|Pearson Correlation|",
xlab="Feature", ylab="Feature")
par(op)
diag(cormat) <- 0
print(max(abs(cormat)))
}
[1]
0.7971926
U-MAP Visualization
of features
The UMAP based on
LASSO on Raw Data
if (nrow(dataframe) < 1000)
{
classes <- unique(dataframe[1:numsub,outcome])
raincolors <- rainbow(length(classes))
names(raincolors) <- classes
datasetframe.umap = umap(scale(dataframe[1:numsub,varlist]),n_components=2)
plot(datasetframe.umap$layout,xlab="U1",ylab="U2",main="UMAP: Original",t='n')
text(datasetframe.umap$layout,labels=dataframe[1:numsub,outcome],col=raincolors[dataframe[1:numsub,outcome]+1])
}

The decorralted
UMAP
if (nrow(dataframe) < 1000)
{
datasetframe.umap = umap(scale(DEdataframe[1:numsub,varlistc]),n_components=2)
plot(datasetframe.umap$layout,xlab="U1",ylab="U2",main="UMAP: After IDeA",t='n')
text(datasetframe.umap$layout,labels=DEdataframe[1:numsub,outcome],col=raincolors[DEdataframe[1:numsub,outcome]+1])
}

Univariate
Analysis
Univariate
univarRAW <- uniRankVar(varlist,
paste(outcome,"~1"),
outcome,
dataframe,
rankingTest="AUC")
100 : mean_jerk_in_air6 200 : disp_index12 300 : mean_speed_in_air17
400 : gmrt_on_paper23
univarDe <- uniRankVar(varlistc,
paste(outcome,"~1"),
outcome,
DEdataframe,
rankingTest="AUC",
)
100 : La_mean_jerk_in_air6 200 : La_disp_index12 300 :
mean_speed_in_air17 400 : gmrt_on_paper23
Final Table
univariate_columns <- c("caseMean","caseStd","controlMean","controlStd","controlKSP","ROCAUC")
##top variables
topvar <- c(1:length(varlist)) <= TopVariables
tableRaw <- univarRAW$orderframe[topvar,univariate_columns]
pander::pander(tableRaw)
| total_time23 |
37.2 |
0.503 |
36.7 |
0.484 |
1.03e-05 |
0.863 |
| total_time15 |
38.1 |
0.875 |
37.1 |
0.421 |
5.44e-01 |
0.844 |
| air_time23 |
36.6 |
0.626 |
35.9 |
0.656 |
6.92e-03 |
0.844 |
| air_time15 |
37.7 |
1.094 |
36.6 |
0.615 |
5.06e-01 |
0.829 |
| total_time17 |
38.5 |
0.681 |
37.8 |
0.614 |
4.00e-03 |
0.824 |
| paper_time23 |
36.4 |
0.439 |
36.0 |
0.231 |
6.72e-01 |
0.814 |
| air_time17 |
37.9 |
0.914 |
37.0 |
0.795 |
3.52e-02 |
0.806 |
| paper_time17 |
37.6 |
0.395 |
37.2 |
0.439 |
1.28e-03 |
0.796 |
| total_time6 |
37.1 |
0.777 |
36.4 |
0.447 |
7.16e-01 |
0.790 |
| air_time16 |
36.4 |
1.131 |
35.2 |
0.867 |
9.38e-01 |
0.787 |
topLAvar <- univarDe$orderframe$Name[str_detect(univarDe$orderframe$Name,"La_")]
topLAvar <- unique(c(univarDe$orderframe$Name[topvar],topLAvar[1:as.integer(TopVariables/2)]))
finalTable <- univarDe$orderframe[topLAvar,univariate_columns]
pander::pander(finalTable)
| air_time23 |
36.612 |
0.626 |
35.858 |
0.656 |
6.92e-03 |
0.844 |
| air_time15 |
37.720 |
1.094 |
36.607 |
0.615 |
5.06e-01 |
0.829 |
| air_time17 |
37.912 |
0.914 |
37.000 |
0.795 |
3.52e-02 |
0.806 |
| air_time16 |
36.357 |
1.131 |
35.240 |
0.867 |
9.38e-01 |
0.787 |
| disp_index23 |
16.116 |
0.194 |
15.926 |
0.166 |
3.43e-01 |
0.787 |
| air_time6 |
36.694 |
0.899 |
35.811 |
0.665 |
7.39e-01 |
0.784 |
| air_time7 |
36.742 |
0.758 |
36.090 |
0.938 |
5.42e-04 |
0.779 |
| gmrt_in_air7 |
32.948 |
0.405 |
33.382 |
0.396 |
9.99e-01 |
0.775 |
| air_time2 |
36.256 |
1.176 |
35.088 |
1.002 |
2.05e-01 |
0.773 |
| mean_speed_in_air17 |
29.116 |
0.493 |
29.551 |
0.389 |
4.85e-01 |
0.766 |
| La_gmrt_on_paper18 |
2.043 |
0.759 |
2.509 |
0.780 |
1.74e-02 |
0.728 |
| La_mean_speed_on_paper2 |
2.121 |
0.820 |
2.805 |
0.864 |
7.19e-01 |
0.724 |
| La_mean_speed_on_paper13 |
-5.051 |
0.068 |
-5.017 |
0.107 |
2.18e-05 |
0.718 |
| La_pressure_mean3 |
0.286 |
0.506 |
0.652 |
0.408 |
2.87e-01 |
0.715 |
| La_max_x_extension14 |
0.825 |
0.702 |
1.355 |
0.687 |
1.20e-01 |
0.712 |
dc <- getLatentCoefficients(DEdataframe)
fscores <- attr(DEdataframe,"fscore")
pander::pander(c(mean=mean(sapply(dc,length)),total=length(dc),fraction=length(dc)/(ncol(dataframe)-1)))
theCharformulas <- attr(dc,"LatentCharFormulas")
finalTable <- rbind(finalTable,tableRaw[topvar[!(topvar %in% topLAvar)],univariate_columns])
orgnamez <- rownames(finalTable)
orgnamez <- str_remove_all(orgnamez,"La_")
finalTable$RAWAUC <- univarRAW$orderframe[orgnamez,"ROCAUC"]
finalTable$DecorFormula <- theCharformulas[rownames(finalTable)]
finalTable$fscores <- fscores[rownames(finalTable)]
Final_Columns <- c("DecorFormula","caseMean","caseStd","controlMean","controlStd","controlKSP","ROCAUC","RAWAUC","fscores")
finalTable <- finalTable[order(-finalTable$ROCAUC),]
pander::pander(finalTable[,Final_Columns])
| total_time23 |
NA |
37.231 |
0.503 |
36.666 |
0.484 |
1.03e-05 |
0.863 |
0.863 |
NA |
| total_time15 |
NA |
38.092 |
0.875 |
37.146 |
0.421 |
5.44e-01 |
0.844 |
0.844 |
NA |
| air_time23 |
NA |
36.612 |
0.626 |
35.858 |
0.656 |
6.92e-03 |
0.844 |
0.844 |
1 |
| air_time231 |
NA |
36.612 |
0.626 |
35.858 |
0.656 |
6.92e-03 |
0.844 |
NA |
NA |
| air_time15 |
NA |
37.720 |
1.094 |
36.607 |
0.615 |
5.06e-01 |
0.829 |
0.829 |
1 |
| air_time151 |
NA |
37.720 |
1.094 |
36.607 |
0.615 |
5.06e-01 |
0.829 |
NA |
NA |
| total_time17 |
NA |
38.526 |
0.681 |
37.848 |
0.614 |
4.00e-03 |
0.824 |
0.824 |
NA |
| paper_time23 |
NA |
36.401 |
0.439 |
36.001 |
0.231 |
6.72e-01 |
0.814 |
0.814 |
NA |
| air_time17 |
NA |
37.912 |
0.914 |
37.000 |
0.795 |
3.52e-02 |
0.806 |
0.806 |
1 |
| air_time171 |
NA |
37.912 |
0.914 |
37.000 |
0.795 |
3.52e-02 |
0.806 |
NA |
NA |
| paper_time17 |
NA |
37.604 |
0.395 |
37.205 |
0.439 |
1.28e-03 |
0.796 |
0.796 |
NA |
| total_time6 |
NA |
37.100 |
0.777 |
36.368 |
0.447 |
7.16e-01 |
0.790 |
0.790 |
NA |
| air_time16 |
NA |
36.357 |
1.131 |
35.240 |
0.867 |
9.38e-01 |
0.787 |
0.787 |
1 |
| air_time161 |
NA |
36.357 |
1.131 |
35.240 |
0.867 |
9.38e-01 |
0.787 |
NA |
NA |
| disp_index23 |
NA |
16.116 |
0.194 |
15.926 |
0.166 |
3.43e-01 |
0.787 |
0.787 |
1 |
| air_time6 |
NA |
36.694 |
0.899 |
35.811 |
0.665 |
7.39e-01 |
0.784 |
0.784 |
1 |
| air_time7 |
NA |
36.742 |
0.758 |
36.090 |
0.938 |
5.42e-04 |
0.779 |
0.779 |
1 |
| gmrt_in_air7 |
NA |
32.948 |
0.405 |
33.382 |
0.396 |
9.99e-01 |
0.775 |
0.775 |
1 |
| air_time2 |
NA |
36.256 |
1.176 |
35.088 |
1.002 |
2.05e-01 |
0.773 |
0.773 |
1 |
| mean_speed_in_air17 |
NA |
29.116 |
0.493 |
29.551 |
0.389 |
4.85e-01 |
0.766 |
0.766 |
4 |
| La_gmrt_on_paper18 |
- (1.991)disp_index18 + gmrt_on_paper18 |
2.043 |
0.759 |
2.509 |
0.780 |
1.74e-02 |
0.728 |
0.647 |
4 |
| La_mean_speed_on_paper2 |
- (1.577)disp_index2 + mean_speed_on_paper2 |
2.121 |
0.820 |
2.805 |
0.864 |
7.19e-01 |
0.724 |
0.720 |
3 |
| La_mean_speed_on_paper13 |
- (1.035)gmrt_on_paper13 + mean_speed_on_paper13 |
-5.051 |
0.068 |
-5.017 |
0.107 |
2.18e-05 |
0.718 |
0.626 |
-1 |
| La_pressure_mean3 |
- (0.265)disp_index3 - (1.199)mean_acc_on_paper3 +
pressure_mean3 |
0.286 |
0.506 |
0.652 |
0.408 |
2.87e-01 |
0.715 |
0.341 |
3 |
| La_max_x_extension14 |
- (2.106)disp_index14 + max_x_extension14 |
0.825 |
0.702 |
1.355 |
0.687 |
1.20e-01 |
0.712 |
0.634 |
-1 |
Comparing IDeA vs
PCA vs EFA
PCA
featuresnames <- colnames(dataframe)[colnames(dataframe) != outcome]
pc <- prcomp(dataframe[,iscontinous],center = TRUE,scale. = TRUE) #principal components
predPCA <- predict(pc,dataframe[,iscontinous])
PCAdataframe <- as.data.frame(cbind(predPCA,dataframe[,!iscontinous]))
colnames(PCAdataframe) <- c(colnames(predPCA),colnames(dataframe)[!iscontinous])
#plot(PCAdataframe[,colnames(PCAdataframe)!=outcome],col=dataframe[,outcome],cex=0.65,cex.lab=0.5,cex.axis=0.75,cex.sub=0.5,cex.main=0.75)
#pander::pander(pc$rotation)
PCACor <- cor(PCAdataframe[,colnames(PCAdataframe) != outcome])
gplots::heatmap.2(abs(PCACor),
trace = "none",
# scale = "row",
mar = c(5,5),
col=rev(heat.colors(5)),
main = "PCA Correlation",
cexRow = 0.5,
cexCol = 0.5,
srtCol=45,
srtRow= -45,
key.title=NA,
key.xlab="Pearson Correlation",
xlab="Feature", ylab="Feature")

EFA
EFAdataframe <- dataframeScaled
if (length(iscontinous) < 2000)
{
topred <- min(length(iscontinous),nrow(dataframeScaled),ncol(predPCA)/2)
if (topred < 2) topred <- 2
uls <- fa(dataframeScaled[,iscontinous],nfactors=topred,rotate="varimax",warnings=FALSE) # EFA analysis
predEFA <- predict(uls,dataframeScaled[,iscontinous])
EFAdataframe <- as.data.frame(cbind(predEFA,dataframeScaled[,!iscontinous]))
colnames(EFAdataframe) <- c(colnames(predEFA),colnames(dataframeScaled)[!iscontinous])
EFACor <- cor(EFAdataframe[,colnames(EFAdataframe) != outcome])
gplots::heatmap.2(abs(EFACor),
trace = "none",
# scale = "row",
mar = c(5,5),
col=rev(heat.colors(5)),
main = "EFA Correlation",
cexRow = 0.5,
cexCol = 0.5,
srtCol=45,
srtRow= -45,
key.title=NA,
key.xlab="Pearson Correlation",
xlab="Feature", ylab="Feature")
}

Effect on CAR
modeling
par(op)
par(xpd = TRUE)
dataframe[,outcome] <- factor(dataframe[,outcome])
rawmodel <- rpart(paste(outcome,"~."),dataframe,control=rpart.control(maxdepth=3))
pr <- predict(rawmodel,dataframe,type = "class")
ptab <- list(er="Error",detail=matrix(nrow=6,ncol=1))
if (length(unique(pr))>1)
{
plot(rawmodel,main="Raw",branch=0.5,uniform = TRUE,compress = TRUE,margin=0.1)
text(rawmodel, use.n = TRUE,cex=0.75)
ptab <- epiR::epi.tests(table(pr==0,dataframe[,outcome]==0))
}

pander::pander(table(dataframe[,outcome],pr))
pander::pander(ptab$detail[c(5,3,4,6),])
| 5 |
diag.ac |
0.920 |
0.869 |
0.955 |
| 3 |
se |
0.921 |
0.845 |
0.968 |
| 4 |
sp |
0.918 |
0.838 |
0.966 |
| 6 |
diag.or |
130.531 |
43.775 |
389.223 |
par(op)
par(xpd = TRUE)
DEdataframe[,outcome] <- factor(DEdataframe[,outcome])
IDeAmodel <- rpart(paste(outcome,"~."),DEdataframe,control=rpart.control(maxdepth=3))
pr <- predict(IDeAmodel,DEdataframe,type = "class")
ptab <- list(er="Error",detail=matrix(nrow=6,ncol=1))
if (length(unique(pr))>1)
{
plot(IDeAmodel,main="IDeA",branch=0.5,uniform = TRUE,compress = TRUE,margin=0.1)
text(IDeAmodel, use.n = TRUE,cex=0.75)
ptab <- epiR::epi.tests(table(pr==0,DEdataframe[,outcome]==0))
}

pander::pander(table(DEdataframe[,outcome],pr))
pander::pander(ptab$detail[c(5,3,4,6),])
| 5 |
diag.ac |
0.914 |
0.862 |
0.951 |
| 3 |
se |
0.888 |
0.803 |
0.945 |
| 4 |
sp |
0.941 |
0.868 |
0.981 |
| 6 |
diag.or |
126.400 |
41.340 |
386.478 |
par(op)
par(xpd = TRUE)
PCAdataframe[,outcome] <- factor(PCAdataframe[,outcome])
PCAmodel <- rpart(paste(outcome,"~."),PCAdataframe,control=rpart.control(maxdepth=3))
pr <- predict(PCAmodel,PCAdataframe,type = "class")
ptab <- list(er="Error",detail=matrix(nrow=6,ncol=1))
if (length(unique(pr))>1)
{
plot(PCAmodel,main="PCA",branch=0.5,uniform = TRUE,compress = TRUE,margin=0.1)
text(PCAmodel, use.n = TRUE,cex=0.75)
ptab <- epiR::epi.tests(table(pr==0,PCAdataframe[,outcome]==0))
}

pander::pander(table(PCAdataframe[,outcome],pr))
pander::pander(ptab$detail[c(5,3,4,6),])
| 5 |
diag.ac |
0.874 |
0.815 |
0.919 |
| 3 |
se |
0.978 |
0.921 |
0.997 |
| 4 |
sp |
0.765 |
0.660 |
0.850 |
| 6 |
diag.or |
141.375 |
31.905 |
626.443 |
par(op)
EFA
EFAdataframe[,outcome] <- factor(EFAdataframe[,outcome])
EFAmodel <- rpart(paste(outcome,"~."),EFAdataframe,control=rpart.control(maxdepth=3))
pr <- predict(EFAmodel,EFAdataframe,type = "class")
ptab <- list(er="Error",detail=matrix(nrow=6,ncol=1))
if (length(unique(pr))>1)
{
plot(EFAmodel,main="EFA",branch=0.5,uniform = TRUE,compress = TRUE,margin=0.1)
text(EFAmodel, use.n = TRUE,cex=0.75)
ptab <- epiR::epi.tests(table(pr==0,EFAdataframe[,outcome]==0))
}

pander::pander(table(EFAdataframe[,outcome],pr))
pander::pander(ptab$detail[c(5,3,4,6),])
| 5 |
diag.ac |
0.925 |
0.876 |
0.960 |
| 3 |
se |
0.888 |
0.803 |
0.945 |
| 4 |
sp |
0.965 |
0.900 |
0.993 |
| 6 |
diag.or |
215.933 |
57.299 |
813.755 |
par(op)